#include "rclcpp/rclcpp.hpp"
#include "custom_srv_msg/srv/custom_srv.hpp"
#include "std_msgs/msg/string.hpp"

using std::placeholders::_1;
using std::placeholders::_2;

namespace ns_service_srv
{
    class service_srv : public rclcpp::Node
    {
    private:
        rclcpp::Service<custom_srv_msg::srv::CustomSrv>::SharedPtr srv_;
        void srv_cb(const std::shared_ptr<custom_srv_msg::srv::CustomSrv::Request> req,
                    std::shared_ptr<custom_srv_msg::srv::CustomSrv::Response> res)
        {
            auto message = std_msgs::msg::String();
            auto message1 = std_msgs::msg::String();
            message.data = req->client;
            res->service = message.data + "   test";
            RCLCPP_INFO(rclcpp::get_logger("rclcpp"),message.data.c_str());
        }
    public:
        service_srv(/* args */);
        ~service_srv();
    };
    
    service_srv::service_srv(/* args */) : Node("service_node")
    {
        srv_ = this->create_service<custom_srv_msg::srv::CustomSrv>("service_cli_demo",std::bind(&service_srv::srv_cb,this,_1,_2));
    }
    
    service_srv::~service_srv()
    {
    }
    
} // namespace ns_service_srv


int main(int argc, char const *argv[])
{
    rclcpp::init(argc,argv);

    // rclcpp::spin(std::make_shared<ns_service_srv::service_srv>());
    auto node = std::make_shared<ns_service_srv::service_srv>();
    RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "server Ready");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}
